import faiss 
import numpy as np

import torch
print(torch.__version__)
torch.rand(1, device="cuda:0")

#实验，faiss 按照添加顺序设置ID
# dim = 256
# nb = 10
# index = faiss.IndexFlatL2(dim)

# xlist = []
# for i in range(10):
#     x = np.zeros((nb,dim))
#     for j in range(nb):
#         x[j:] = j
#         xlist.append(x[j])
    
#     index.add(x)
# q = np.zeros((1,dim))
# q[0:] = 3
# dis,pre = index.search(q,3)
# q[0:] = 4
# dis,pre = index.search(q,3)

#实验unique

# arr = np.array([[1,1,2,2,2,3],
#                 [4,4,5,5,5,6]])

# res = np.unique(arr)
# dict_k_v = dict()
# for k in res:
#     res = np.where(arr == k)
#     dict_k_v[k] = len(res[0])
# print(dict_k_v)

# def get_sorted_list(d, reverse=False):
#     return sorted(d.items(), key=lambda x:x[1], reverse=reverse)

# d_list = get_sorted_list(dict_k_v,True)
# vv = [item[0] for item in d_list[0:3]]
# print(d_list[:5])


#class 测试
# from MyClass import MyClass

# m1 = MyClass()
# m1.aa = 3
# print(m1.aa)

#numpy.lexsort 测试
# import numpy as np
# x = np.array([[9,6,7],[9,4,7],[8,2,3]])
# print(x)
# # x_index为索引值
# # !!!注意首要条件放在后面
# x_index = np.lexsort((x[:,1],x[:,0]))
# # x_sort排序后的值
# x_sort = x[x_index]
# print(x_sort)